#MONSTER TESTS
import unittest

import game.monster.models as m
import game.attributes.models as a

class basicTest(unittest.TestCase):
	def setUp(self):
		self.monsterType = m.monsterType.objects.create(name='testType') 
		self.nrmlSize = a.size.objects.create(name='Normal')
		self.species = m.species.objects.create(name='testSpecies',
			type = self.monsterType, size= self.nrmlSize,
			str=10, dex=10, con=10, int=10, speed=10)
	
	def tearDown(self):
		m.monsterType.delete(self.monsterType) 
		a.size.delete(self.nrmlSize)
		m.species.delete(self.species)
		
class baseMonsterTest(basicTest):
	def setUp(self):
		basicTest.setUp(self)
		self.trait1 = a.trait.objects.create(name='Hands')
		self.trait2 = a.trait.objects.create(name='Head')
		self.trait3 = a.trait.objects.create(name='Torso')
		self.species.traits.add(self.trait1)
		self.individual = m.individual.objects.create(species=self.species,
			firstName = 'test', lastName='Monster', totalHP = 10, 
			totalMP = 10)
		self.individual.traits_aquired.add(self.trait2)
		
	def tearDown(self):
		basicTest.tearDown(self)
		#m.monsterType.delete(self.monsterType) 
		#a.size.delete(self.nrmlSize)
		#m.species.delete(self.species)
		a.trait.delete(self.trait1)
		a.trait.delete(self.trait2)
		a.trait.delete(self.trait3)
		m.individual.delete(self.individual)
	
	def testTraits(self):
		"""
		Tests that an individual is aware of its own traits and the
		traits of its species
		"""
		self.assertEquals(self.species.hasTrait(self.trait1), True)
		self.assertEquals(self.individual.hasTrait(self.trait1), True)
		self.assertEquals(self.individual.hasTrait(self.trait2), True)
		self.assertEquals(self.individual.hasTrait(self.trait3), False)
	
	def testAddHDMD(self):
		"""
		Tests that a HD and MD can be added to the individual
		"""
		self.assertEquals(self.individual.HDTotal, 1)
		self.assertEquals(self.individual.MDTotal, 1)
		self.assertEquals(self.individual.addHD(), 1)
		self.assertEquals(self.individual.HDTotal, 2)
		self.assertEquals(self.individual.totalHP > 10, 1)
		self.assertEquals(self.individual.addMD(), 1)
		self.assertEquals(self.individual.MDTotal, 2)
		self.assertEquals(self.individual.totalMP > 10, 1)
	
class baseGroupTest(basicTest):
	def setUp(self):
		basicTest.setUp(self)
		self.individual1 = m.individual.objects.create(species=self.species,
			firstName = 'test1', lastName='Monster')
		self.individual2 = m.individual.objects.create(species=self.species,
			firstName = 'test2', lastName='Monster')
		self.individual3 = m.individual.objects.create(species=self.species,
			firstName = 'test3', lastName='Monster')
		self.individual4 = m.individual.objects.create(species=self.species,
			firstName = 'test4', lastName='Monster')
		self.group = m.group.objects.create()
		self.group2 = m.group.objects.create()
		self.individual1.group=self.group
		self.individual1.save()
		self.individual2.group=self.group
		self.individual2.save()
		self.individual3.group=self.group
		self.individual3.save()
		self.individual4.group=self.group2
		self.individual4.save()
		
	def tearDown(self):
		basicTest.tearDown(self)
		m.individual.delete(self.individual1)
		m.individual.delete(self.individual2)
		m.individual.delete(self.individual3)
		m.individual.delete(self.individual4)
		m.group.delete(self.group)
		m.group.delete(self.group2)
		
	def testGroup(self):
		"""
		Test group functions
		"""
		self.assert_(len(self.group.allMonsters()), 3)
		self.assert_(len(self.group2.allMonsters()),1)
